package com.kanqiubao.kq.view.dialog;

import android.content.Context;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;

import com.kanqiubao.kq.R;
import com.kanqiubao.kq.utils.StringUtil;
import com.lxj.xpopup.core.AttachPopupView;
import com.lxj.xpopup.util.XPopupUtils;

/**
 * 屏蔽比分啥的
 */
public class LivePbBfenPopupView extends AttachPopupView implements CompoundButton.OnCheckedChangeListener {
    public LivePbBfenPopupView(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.live_lw_pb_select_layout;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        ((CheckBox) findViewById(R.id.rd1)).setOnCheckedChangeListener(this);
        ((CheckBox) findViewById(R.id.rd2)).setOnCheckedChangeListener(this);
        ((CheckBox) findViewById(R.id.rd3)).setOnCheckedChangeListener(this);
    }

    @Override
    protected void onShow() {
        super.onShow();
    }

    @Override
    protected void onDismiss() {
        super.onDismiss();
        if (mSelelctIml != null) {
            mSelelctIml.dissmiss(s);
        }
    }

    @Override
    protected int getMaxHeight() {
        return (int) (XPopupUtils.getWindowHeight(getContext()) * .85f);
    }

    String s = "";

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        s = "";
        LinearLayout root = findViewById(R.id.root_id);
        for (int i = 0; i < root.getChildCount(); i++) {
            if (((CheckBox) root.getChildAt(i)).isChecked()) {
                //有一个选中改变状态
                s += i + ",";

            }
        }
        if (!StringUtil.isEmptyString(s)) {
            s = s.substring(0, s.length() - 1);
        }
        if (mSelelctIml != null) {
            mSelelctIml.call(s);
        }
    }

    private selelctIml mSelelctIml;

    public LivePbBfenPopupView setmSelelctIml(selelctIml s) {
        mSelelctIml = s;
        return this;
    }

    public interface selelctIml {
        void call(String s);

        void dissmiss(String s);
    }
}